import request from '../utils/request'

// 分页查询学生列表
export function getStudentList(params) {
  // 确保所有必需参数都有值
  const requestParams = {
    pageNum: params.pageNum || 1,
    pageSize: params.pageSize || 10,
    stuNo: params.stuNo !== undefined && params.stuNo !== '' ? params.stuNo : -1,
    stuName: params.stuName !== undefined ? params.stuName : '',
    stuAge: params.stuAge !== undefined ? params.stuAge : '',
    stuSex: params.stuSex !== undefined && params.stuSex !== '' ? params.stuSex : -1,
    stuPhone: params.stuPhone !== undefined ? params.stuPhone : '',
    stuDept: params.stuDept !== undefined ? params.stuDept : ''
  }
  
  console.log('发送请求参数:', requestParams) // 调试用
  console.log('原始参数:', params) // 调试用
  
  return request({
    url: '/student/listPage',
    method: 'get',
    params: requestParams
  })
}

// 根据id查询学生详情
export function getStudentDetail(id) {
  return request({
    url: '/student/select',
    method: 'get',
    params: { id }
  })
}

// 新增学生
export function addStudent(data) {
  return request({
    url: '/student/save',
    method: 'post',
    data
  })
}

// 编辑学生
export function updateStudent(data) {
  return request({
    url: '/student/update',
    method: 'put',
    data
  })
}

// 删除学生
export function deleteStudent(id) {
  return request({
    url: '/student/delete',
    method: 'delete',
    params: { id }
  })
}